package com.example.onlineeducation.mapper

import com.example.onlineeducation.data.entity.ExamAnswerEntity
import com.example.onlineeducation.data.entity.ExamOptionEntity
import com.example.onlineeducation.data.entity.ExamResultDetailEntity
import com.example.onlineeducation.data.json.ExamResultDetailJson
import com.yc.jetpacklib.extension.ycIsNotEmpty
import com.yc.jetpacklib.extension.ycToNoEmpty
import com.yc.jetpacklib.mapper.IMapper

class ExamResultDetailMapper : IMapper<ExamResultDetailJson, ExamResultDetailEntity> {
    override fun map(input: ExamResultDetailJson): ExamResultDetailEntity {

        val answerInfo = if (input.answerInfo.ycIsNotEmpty()) {
            input.answerInfo?.map { item ->//题目列表
                ExamAnswerEntity(
                    item!!.questionId,
                    item.content.ycToNoEmpty(),
                    item.type,
                    item.isRight,//该题是否答对   0-否,1-是
                    item.userSelectOptionIds,
                    item.options?.map {//每题选项
                        ExamOptionEntity(
                            it?.content.ycToNoEmpty(), //选项内容
                            it?.id,
                            it?.isAnswer,
                            it?.isDelete,
                            it?.materialId,
                            it?.questionId
                        )
                    }
                )
            }
        } else {
            null
        }

        return ExamResultDetailEntity(
            answerInfo,
            input.isPass,//是否通过,0-未通过,1-已通过
            "${input.getCorrectRate()}%",//正确率
            "共${input.answerInfo?.size.ycToNoEmpty(0)}道题目",
            input.examName.ycToNoEmpty()//考试名称
        )

    }
}
